<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>系统仪表盘 - MES系统</title>
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<body>
    <div class="container">
        <!-- Header -->
        <header class="header">
            <h1><i class="fas fa-tachometer-alt"></i> 系统仪表盘</h1>
            <div class="user-info">
                <span id="currentTime"></span>
                <a href="index.html" class="btn btn-secondary">
                    <i class="fas fa-home"></i> 返回主页
                </a>
            </div>
        </header>

        <!-- Navigation -->
        <nav class="sidebar">
            <ul class="nav-menu">
                <li class="nav-item active">
                    <i class="fas fa-tachometer-alt"></i>
                    <span>仪表盘</span>
                </li>
                <li class="nav-item">
                    <a href="products.html">
                        <i class="fas fa-box"></i>
                        <span>产品管理</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="workorders.html">
                        <i class="fas fa-clipboard-list"></i>
                        <span>工单管理</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="production-records.html">
                        <i class="fas fa-cogs"></i>
                        <span>生产记录</span>
                    </a>
                </li>
            </ul>
        </nav>

        <!-- Main Content -->
        <main class="main-content">
            <div class="page-header">
                <h2>系统概览</h2>
                <button class="btn btn-primary" onclick="refreshDashboard()">
                    <i class="fas fa-sync-alt"></i> 刷新数据
                </button>
            </div>

            <!-- 统计卡片 -->
            <div class="dashboard-grid">
                <div class="stats-card">
                    <div class="stats-icon products">
                        <i class="fas fa-box"></i>
                    </div>
                    <div class="stats-info">
                        <h3 id="totalProducts">-</h3>
                        <p>产品总数</p>
                        <small class="stats-detail">
                            <span id="productCategories">-</span> 个分类
                        </small>
                    </div>
                </div>
                
                <div class="stats-card">
                    <div class="stats-icon workorders">
                        <i class="fas fa-clipboard-list"></i>
                    </div>
                    <div class="stats-info">
                        <h3 id="totalWorkOrders">-</h3>
                        <p>工单总数</p>
                        <small class="stats-detail">
                            进行中: <span id="inProgressOrders">-</span>
                        </small>
                    </div>
                </div>
                
                <div class="stats-card">
                    <div class="stats-icon production">
                        <i class="fas fa-cogs"></i>
                    </div>
                    <div class="stats-info">
                        <h3 id="totalProductionRecords">-</h3>
                        <p>生产记录</p>
                        <small class="stats-detail">
                            今日: <span id="todayRecords">-</span>
                        </small>
                    </div>
                </div>
                
                <div class="stats-card">
                    <div class="stats-icon progress">
                        <i class="fas fa-chart-line"></i>
                    </div>
                    <div class="stats-info">
                        <h3 id="completionRate">-%</h3>
                        <p>完成率</p>
                        <small class="stats-detail">
                            本月平均
                        </small>
                    </div>
                </div>
            </div>

            <!-- 图表和详细信息 -->
            <div class="dashboard-details">
                <div class="chart-section">
                    <div class="card">
                        <div class="card-header">
                            <h3>工单状态分布</h3>
                            <select id="statusDateRange" class="form-control" style="width: auto;">
                                <option value="7">最近7天</option>
                                <option value="30">最近30天</option>
                                <option value="90">最近90天</option>
                            </select>
                        </div>
                        <div class="card-body">
                            <div id="workOrderChart" class="chart-container">
                                <div class="chart-placeholder">
                                    <i class="fas fa-chart-pie"></i>
                                    <p>加载中...</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="activity-section">
                    <div class="card">
                        <div class="card-header">
                            <h3>最近活动</h3>
                            <button class="btn btn-sm btn-secondary" onclick="loadRecentActivities()">
                                <i class="fas fa-refresh"></i>
                            </button>
                        </div>
                        <div class="card-body">
                            <div class="activity-list" id="recentActivities">
                                <div class="loading">
                                    <i class="fas fa-spinner fa-spin"></i>
                                    <span>加载中...</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 快速操作区域 -->
            <div class="quick-actions">
                <div class="card">
                    <div class="card-header">
                        <h3>快速操作</h3>
                    </div>
                    <div class="card-body">
                        <div class="action-buttons">
                            <a href="products.html" class="action-btn">
                                <i class="fas fa-plus"></i>
                                <span>添加产品</span>
                            </a>
                            <a href="workorders.html" class="action-btn">
                                <i class="fas fa-file-plus"></i>
                                <span>创建工单</span>
                            </a>
                            <a href="production-records.html" class="action-btn">
                                <i class="fas fa-play"></i>
                                <span>记录生产</span>
                            </a>
                            <button class="action-btn" onclick="generateReport()">
                                <i class="fas fa-chart-bar"></i>
                                <span>生成报表</span>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </main>
    </div>

    <!-- Toast Notification -->
    <div id="toast" class="toast"></div>

    <script src="js/dashboard.js"></script>
</body>
</html>